<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="../css/style.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../script/common.js" ></script>
<script type="text/javascript" src="../script/jquery-1.8.1.min.js" ></script>
<script type="text/javascript" >
function showAllDetail(obj){
	window.location.href="main/pomain/ShowAllPomainDetail?poId="+obj;
}
var currentPage=1;
var payType;
var status;
function search(obj){
	if(obj==1){
		payType=1;status=2;
	}else if(obj==2){
		payType=2;status=4;
	}else if(obj=3){
		payType=3;status=2;
	}
	show();
}
function test(){
	payType = $("#payType").text();
	status = $("#status").text();
	show();
}
function show(){
	$.ajax({
		type:'post',
		url:'main/pomain/ShowEndPomain',
		data:{payType:payType,status:status,currentPage:currentPage},
		dataType:'json', //获得的json格式的数据将被转换成JS对象
		success:function(msg){
			$("#payType").text(msg.dataList[0].payType);
			$("#status").text(msg.dataList[0].status);
			$("#body").children().remove();//添加数据之前先清空数据
			for(var i=0;i<msg.dataList.length;i++){
				if(msg.dataList[i].payType==1){
					msg.dataList[i].payType="货到付款";
				}else if(msg.dataList[i].payType==2){
					msg.dataList[i].payType="款到发货";
				}else if(msg.dataList[i].payType==3){
					msg.dataList[i].payType="预付款到发货";
				}
				if(msg.dataList[i].status==1){
					msg.dataList[i].status="新增";
				}else if(msg.dataList[i].status==2){
					msg.dataList[i].status="已付款";
				}else if(msg.dataList[i].status==3){
					msg.dataList[i].status="已预付";
				}else if(msg.dataList[i].status==4){
					msg.dataList[i].status="已入库";
				}else if(msg.dataList[i].status==5){
					msg.dataList[i].status="已了结";
				}
				$("#body").append("<tr align='center'><td ondblclick='showAllDetail("+msg.dataList[i].poId+")'><span style='color:blue'>"+msg.dataList[i].poId+"</span></td><td>"+msg.dataList[i].createTime+"</td><td>"
						+msg.dataList[i].venderName+"</td><td>"+msg.dataList[i].account+"</td><td>"+msg.dataList[i].tipFee+
						"</td><td>"+msg.dataList[i].productTotal+"</td><td>"+msg.dataList[i].poTotal+"</td><td>"+msg.dataList[i].payType+
						"</td><td>"+msg.dataList[i].prePayFee+"</td><td>"+msg.dataList[i].status+"</td><td><span onclick='end("+msg.dataList[i].poId+")'>了结</span></td></tr>");
			}
			//将当前和总页数放在节点对象中
			$("#cp").text(msg.currentPage);
			$("#ap").text(msg.pageCount);
			
		}
	});
}
function end(obj){
	if(confirm("是否了结 ？")){
		$.ajax({
			type:"post",
			url:"main/pomain/EndPomain",
			data:{poId:obj},
			success:function(msg){
				alert(msg);
				test();
				
			}
		});
	}
}
function goPage(obj){
	if(obj=='first'){
		currentPage=1;
		test();
	}else if(obj=='front'){
		if(currentPage==1){
			alert("已经是首页了");
		}else{
			currentPage-=1;
			test();
		} 
	}else if(obj=='next'){
		if(currentPage==$("#ap").text()){
			alert("已经是末页了");
		}else{
			currentPage+=1;
			test();
		}
	}else{
		if(currentPage+1<=$("#ap").text()){
			currentPage=$("#ap").text();
			test();
		}
	}
}
</script>

</head>
<body>
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td nowrap class="title1">您的位置：工作台面－－采购管理－－了结采购单</td>
	  </tr>
</table>
<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="30px" nowrap class="toolbar">&nbsp;</td>
	<td nowrap class="toolbar">&nbsp;</td>
    <td width="60px" nowrap class="toolbar" onMouseOver="OMO(event)" onMouseOut="OMOU(event)" onclick="search(1)"><a>货到付款</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
    <td width="60px" nowrap class="toolbar" onMouseOver="OMO(event)" onMouseOut="OMOU(event)" onclick="search(2)"><a>款到发货</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
    <td width="60px" nowrap class="toolbar" onMouseOver="OMO(event)" onMouseOut="OMOU(event)" onclick="search(3)"><a>预付款到发货</a></td>
    <td width="20px" nowrap class="toolbar">|</td>
  </tr>
</table>
	<table width="100%"  border="0" cellpadding="0" cellspacing="1">
		<tr>
			<td class="title1">采购单编号</td>
			<td class="title1">创建日期</td>
			<td class="title1">供应商名称</td>
			<td class="title1">创建用户</td>
			<td class="title1">附加费用</td>
			<td class="title1">采购产品总价</td>
			<td class="title1">采购单总价格</td>
			<td class="title1">付款方式</td>
			<td class="title1">最低预付款金额</td>
			<td class="title1">处理状态</td>
			<td class="title1">操作</td>
		</tr>
		<tbody id="body"></tbody>
	
	</table><br/>
	<center>
	<input type="button" value="首页" onclick="goPage('first')"/>
	<input type="button" value="上一页" onclick="goPage('front')" />
	<input type="button" value="下一页" onclick="goPage('next')"/>
	<input type="button" value="末页" onclick="goPage('end')"/>
	当前第<span id="cp"></span>页
    	共<span id="ap"></span>页
    	<span id="payType" hidden></span>
    	<span id="status" hidden></span>
    	</td>
    </center>
</body>
</html>